# include <ros/ros.h>
# include <geometry_msgs/Twist.h>

int main(int argc, char *argv[])
{
    //初始化节点
    ros::init(argc, argv, "vel_node");

    //召唤大管家NodeHandle
    ros::NodeHandle n;

    //3.在节点中，向ROS大管家Nodehandle申请发布话题/cmd_vel,并拿到发布对象vel_pub
    ros::Publisher vel_pub = n.advertise<geometry_msgs::Twist>("/cmd_vel", 10);

    //4.构建一个geometry_msgs/Twist消息类型的变量vel_msg，用来承载要发布的速度值。
    geometry_msgs::Twist vel_msg;
    vel_msg.linear.x = 0;
    vel_msg.linear.y = 0;
    vel_msg.linear.z = 0;
    vel_msg.angular.x = 0;
    vel_msg.angular.y = 0;
    vel_msg.angular.z = 0.5;

    //5.开启一个while循环，不停地使用vel_pub对象发送速度消息包vel_msg.
    ros::Rate r(30); // 控制while循环次数
    while (ros::ok())
    {
        vel_pub.publish(vel_msg);
        r.sleep();
    }
    return 0;
}